package com.yxw.springmvc.userBehavior.service.impl;

import com.yxw.springmvc.userBehavior.convert.BasicCustConvert;
import com.yxw.springmvc.userBehavior.mapper.BasicCustMapper;
import com.yxw.springmvc.userBehavior.model.BasicCust;
import com.yxw.springmvc.userBehavior.request.BasicCustAddRequest;
import com.yxw.springmvc.userBehavior.service.CustManageService;
import com.yxw.springmvc.userBehavior.util.CollectionUtils;
import com.yxw.springmvc.userBehavior.util.SequenceUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by hp on 2016/10/9.
 */
@Service
public class CustManageServiceImpl implements CustManageService{

    @Resource
    private BasicCustConvert basicCustConvert;

    @Resource
    private SequenceUtil sequenceUtil;

    @Resource
    private BasicCustMapper basicCustMapper;

    @Override
    public BasicCust add(BasicCustAddRequest request) {
        if(CollectionUtils.isEmpty(request)){
           return null;
        }
        String code = sequenceUtil.getSequence();
        BasicCust cust = basicCustConvert.convert(request);
        cust.setCustCode(code);
        basicCustMapper.insert(cust);
        return cust;
    }
}
